<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const fileTypeMapping = new Map([
            ['md', 'markdown'],
            ['doc', 'word'],
            ['docx', 'word'],
            ['html', 'web'],
            ['xls', 'excel'],
        ]);

        const input = [
            'js-this.md',
            'vue.docx',
            'js-class.md',
            'react.xixi.doc',
            'mp.xls',
            'fe06.xls',
            'fe06.heihei.xls',
            'index.html',
        ];

        const output = {
            word: [
                'vue.docx',
                'react.xixi.doc',
            ],
            markdown: [
                'js-this.md',
                'js-class.md',
            ],
            excel: [
                'mp.xls',
                'fe06.xls',
                'fe06.heihei.xls',
            ],
            web: [
                'index.html',
            ],
        };

        function getFileCount (input) {
            const res = {};
            for (const item of input) {
                // item: 'js-this.md',
                const suffix = item.split('.').pop();
                // 'md'>>>'markdown'
                const fileType = fileTypeMapping.get(suffix);
                if (!res[fileType]) {
                    res[fileType] = [item];
                } else {
                    res[fileType].push(item);
                }
            }
            return res;
        }
        console.log(getFileCount(input));


        function getFileCount1 (input) {
            return input.reduce((prev, current) => {
                const suffix = current.split('.').pop();
                const fileType = fileTypeMapping.get(suffix);
                if (!prev[fileType]) {
                    prev[fileType] = [current];
                } else {
                    prev[fileType].push(current);
                }
                return prev;
            },{})
        }
        console.log(getFileCount1(input));
    </script>
</body>
</html>